package com.cap10.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

/**
 * 日志切面类
 */
@Aspect
public class LogAspects {

    @Pointcut(value = "execution(public int com.cap10.aop.Calculator.*(..))")//切入点
    public void pointCut() {
    }


    //@before代表在目标方法执行前切入， 并指定在哪个方法前切入
    @Before("pointCut()")
    public void logStart(JoinPoint joinPoint) {
        System.out.println(joinPoint.getSignature().getName() + "除法运行。...参数列表是:{"+ Arrays.toString(joinPoint.getArgs()) +"}");
    }

    @After("pointCut()")
    public void logEnd(JoinPoint joinPoint) {
        System.out.println(joinPoint.getSignature().getName() +"除法结束......");
    }

    @AfterReturning(value = "pointCut()", returning = "result")
    public void logReturn(Object result) {
        System.out.println("除法正常返回.....运行结果为：{" + result + "}");
    }

    @AfterThrowing(value = "pointCut()", throwing = "exception")
    public void logException(Exception exception) {
        System.out.println("运行异常.....异常信息为：{" + exception + "}");
    }

    /*@Around("pointCut()")
    public Object Around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("@Around执行目标方法之前...");
        Object o = proceedingJoinPoint.proceed();
        System.out.println("@Around执行目标方法之后...");
        return o;
    }*/
}
